var jsonList = {};
jsonList.state=1;
var page = 1;
var rows = 10;
$(function (){
    getList();
    //获取默认频道
    $.ajax({
        url: baseNews + "/api/data/special/channel/select",
        success: function (res) {
            console.log(res);
            if (res.code == 0) {
                var obj = $(".sh_pind");
                $(res.data).each(function (index, key) {
                    obj.append("<option value='" + key.id + "'>" + key.value + "</option>");
                })
            }
        }
    })
    //搜索
    $(".sh_ztzt").change(function () {
        jsonList.state = $(this).val();
    })
    $(".sh_pind").change(function () {
        jsonList.cid  = $(this).val();
    })
    $(".sh_ss").on("click",function (){
        var zt_id = $(".zt_id").val();//专题id
        var zt_mc = $(".zt_mc").val();//专题名称
        if (zt_id!=""){
            jsonList.id = zt_id
        }
        if (zt_mc != "") {
            jsonList.title = zt_mc
        }
        console.log(jsonList,888888);
        getList();
    })
    //审核通过
    $(".sh_tg").on('click',function (){
        var numCount = 0;
        var ids = '';
        $(".xuanze").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
            }
        })
        ids = ids.substring(0, ids.length-1);
        //console.log(ids, 555);
        if (numCount >= 1) {
            //进行下一步
            var json = {}
            var result = JSON.stringify(json);
            zeroModal.confirm("确定要审核通过该专题吗？", function () {
                //置顶确认请求数据
                $.ajax({
                    url: baseNews + "/api/data/audit/special?ids=" + ids +"&audit=true",
                    type: "post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data: result,
                    success: function (res) {
                        if (res.code == 0) {
                            location.reload();
                            console.log(res,88888)
                        } else {
                            zeroModal.alert('审核专题失败');
                        }
                    }
                })
            });
        } else {
            //遮罩层提示
            zeroModal.alert('请选择至少一条专题审核');

        }
    })
    //审核失败
    $(".sh_sb").on('click', function () {
        var numCount = 0;
        var ids = '';
        $(".xuanze").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
            }
        })
        ids = ids.substring(0, ids.length - 1);
        //console.log(ids, 555);
        if (numCount >= 1) {
            //进行下一步
            var json = {}
            var result = JSON.stringify(json);
            zeroModal.confirm("确定要审核失败该专题吗？", function () {
                //置顶确认请求数据
                $.ajax({
                    url: baseNews + "/api/data/audit/aticle?audit=false&ids=" + ids,
                    type: "post",
                    headers: { 'Content-Type': 'application/json' },
                    dataType: "json",
                    data: result,
                    success: function (res) {
                        if (res.code == 0) {
                            location.reload();
                        } else {
                            zeroModal.alert('审核专题失败');
                        }
                    }
                })
            });
        } else {
            //遮罩层提示
            zeroModal.alert('请选择至少一条专题审核');

        }
    })
})
function getList() {
    var result = JSON.stringify(jsonList);
    $.ajax({
        url: baseNews + "/api/data/common/special/list?page=" + page + "&rows=" + rows,
        type: "post",
        headers: { 'Content-Type': 'application/json' },
        dataType: "json",
        data: result,
        success: function (res) {
            console.log(res, 666);
            if (res.code == 0) {
                var result = res.data;
                var list = result.list;
                var html = "";
                $("#page").paging({
                    pageNo: page,
                    totalPage: result.totalpage,
                    totalSize: result.totals,
                    callback: function (num) {
                        page = num;
                        getList();
                    }
                })
                $(".tab_content").empty();
                $(list).each(function (index, key) {
                    console.log(index);
                    var state = key.state;
                    var newState = "";
                    if (state == 1) {
                        newState = "待审核";
                    }
                    if (state == 2) {
                        newState = "待发布";
                    }
                    if (state == 3) {
                        newState = "已发布";
                    }
                    if (state == 10) {
                        newState = "有更新";
                    }
                    if (state == -1) {
                        newState = "审核失败";
                    }
                    if (state == -2) {
                        newState = "撤销发布";
                    }
                    html += `<div class="div">
					<div class="b-t-s ww bor b-s-active">
						<input type="checkbox" oid="${key.id}" name='sex' class="xuanze">
					</div>
					<div class="b-t-s ww b-s-active">${key.id}</div>
					<div class="b-t-s ww b-s-active">${key.title}</div>
					<div class="b-t-s ww b-s-active">${newState}</div>
                    <div class="b-t-s ww bor b-s-active">${key.cname}</div>
                    <div class="b-t-s ww">${key.articles}</div>
					<div class="b-t-s ww b-s-active"></div>
					<div class="b-t-s ww b-s-active">${key.top == true ? "是" : "否"}</div>
					<div class="b-t-s ww b-s-active">${key.click}</div>
					<div class="b-t-s ww b-s-active">${key.collect}</div>
					<div class="b-t-s ww b-s-active">${key.follow}</div>
					<div class="b-t-s ww b-s-active">${key.pass}</div>
					<div class="b-t-s ww b-s-active">${key.comment}</div>
					<div class="b-t-s ww b-s-active">${key.heating}</div>
					<div class="b-t-s ww b-s-active">${key.cooling}</div>
					<div class="b-t-s ww b-s-active">${key.hot}</div>
					<div class="b-t-s ww b-s-active">${key.username}</div>
					<div class="b-t-s ww b-s-active">${key.createtime}</div>
					<div class="b-t-s ww b-s-active">${key.updatetime}</div>
					<div class="b-t-s ww b-s-active">${key.atime?key.atime:""}</div>
					<div class="b-t-s ww b-s-active">${key.rtime?key.rtime:""}</div>
					</div>`;
                })
                $(".tab_content").append(html);
            }
            //审核成功
        }

    })
    //分页

}